﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ClientRegister
{
    public partial class ChangeInfoPersonForm : Form
    {

        public string IDEmp { set; get; }
        public string NameEmp { set; get; }

        public string ID { set; get; }
        public string FullName { set; get; }
        public string GenderId { set; get; }
        public string Birthday { set; get; }
        public string Career { set; get; }
        public string Email { set; get; }
        public string Phone { set; get; }
        public string Address { set; get; }
        public string Note { set; get; }
        public string CreateDateTime { set; get; }

        SynchronizeData sync = new SynchronizeData();

        public ChangeInfoPersonForm()
        {
            InitializeComponent();
        }

        private void InfoPersonForm_Load(object sender, EventArgs e)
        {
            ////Load du lieu tu server
            //sync.GetDataForInsertMethodWithID(sync.studentTb, sync.insertcol);
            //sync.GetDataForInsertMethodWithID(sync.studentTb, sync.updatecol);

            txtID.Text = ID;
            txtName.Text = FullName;
            txtGender.Text = GenderId;
            txtBirthday.Text = DateTime.Parse(Birthday).ToShortDateString();
            txtJob.Text = Career;
            txtEmail.Text = Email;
            txtPhone.Text = Phone;
            txtAdress.Text = Address;
            txtCreateDateTime.Text = CreateDateTime;

        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (txtNote.Text == "")
                MessageBox.Show("Ghi chú nội dung chỉnh sửa");
            else
            {
                string NoteTotal = "";
                NoteTotal += Note;
                NoteTotal += "Chinh sua ngay: " + DateTime.Now.ToString() + " Boi Nhan Vien: ID: " +IDEmp+ ", Ten: "+NameEmp+"\n";
                NoteTotal += "- Noi dung chinh sua: " + txtNote.Text + "\n";
                if (txtName.Text != FullName)
                    NoteTotal += "- " + FullName + "\n";
                if (txtGender.Text != GenderId)
                    NoteTotal += "- " + GenderId + "\n";
                if (txtBirthday.Text != DateTime.Parse(Birthday).ToShortDateString())
                    NoteTotal += "- " + DateTime.Parse(Birthday).ToShortDateString() + "\n";
                if (txtJob.Text != Career)
                    NoteTotal += "- " + Career + "\n";
                if (txtEmail.Text != Email)
                    NoteTotal += "- " + Email + "\n";
                if (txtPhone.Text != Phone)
                    NoteTotal += "- " + Phone + "\n";
                if (txtAdress.Text != Address)
                    NoteTotal += "- " + Address + "\n";


                StudentDataProvider std = new StudentDataProvider();
                int result = std.UpdateStudent(txtID.Text.ToString(), txtName.Text, int.Parse(txtGender.Text.ToString()),
                    txtBirthday.Text, txtJob.Text, txtEmail.Text, int.Parse(txtPhone.Text.ToString()), txtAdress.Text, NoteTotal);

                if (result == 1)
                    MessageBox.Show("Chỉnh sửa thành công");
                else MessageBox.Show("Chỉnh sửa không thành công");
            }
        //=============================================================================
            

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
